import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
  Query,
} from '@nestjs/common';
import { BasicService } from './basic.service';
import { newFolderDto, moveFilesDto } from './basic.dto';

@Controller('basic')
export class BasicController {
  constructor(private readonly basicService: BasicService) {}

  //得到左侧文件树结构
  @Get('/fileTree')
  async getFileTree(@Req() req) {
    const userId = req.user.user_id as number;
    return await this.basicService.getCloudDocRoot(userId);
  }

  //根据文件夹id获取列表
  @Get('fileList/:folderId')
  async getFileList(@Req() req, @Param('folderId') folderId: string) {
    const userId = req.user.user_id as number;
    return await this.basicService.getFilesByParentId(folderId, userId);
  }

  //新建文件夹：前端判断有权限后才调用
  @Post('/newFolder')
  async newFolder(@Req() req, @Body() body: newFolderDto) {
    const userId = req.user.user_id as number;
    return await this.basicService.newFolder(userId, body);
  }

  //重命名文件/文件夹：前端判断有权限后才调用
  @Patch('/renameFile/:id/:newName')
  async renameFile(@Param('id') id: string, @Param('newName') newName: string) {
    return this.basicService.renameFile(id, newName);
  }

  //放到回收站，将status设为deleted
  @Patch('/tempDeleteFile/:id')
  async temDeleteFile(@Param('id') id: string) {
    return this.basicService.temDeleteFile(id);
  }

  //还原文件，将文件/文件夹的status置为active
  @Patch('/restoreFile/:id')
  async restoreFile(@Param('id') id: string) {
    return this.basicService.restoreFile(id);
  }

  //获取回收站文件，只获取第一层，文件夹不可展开
  @Get('/trashFile')
  async trashFile(@Req() req) {
    const userId = req.user.user_id as number;
    return this.basicService.trashFile(userId);
  }

  //移动文件，将文件/文件夹批量移动到某个文件夹目录下
  @Patch('/move')
  async moveFile(@Body() body: moveFilesDto) {
    return this.basicService.moveFile(body);
  }

  //获取收藏列表
  @Get('collectList')
  async collectList(@Req() req) {
    const userId = req.user.user_id as number;
    return this.basicService.collectList(userId);
  }
  //收藏文件
  @Patch('/collect/:fileId')
  async collectFile(@Req() req, @Param('fileId') fileId: string) {
    const userId = req.user.user_id as number;
    return this.basicService.collectFile(userId, fileId);
  }
  //取消收藏
  @Delete('/unCollect/:fileId')
  async unCollectFile(@Req() req, @Param('fileId') fileId: string) {
    const userId = req.user.user_id as number;
    return this.basicService.unCollectFile(userId, fileId);
  }

  //彻底删除文件，这个应该得用和oss交流，删除就不用前端和oss直连了
  @Delete('/deleteFile/:id')
  async deleteFile(@Req() req, @Param('id') id: string) {
    const userId = req.user.user_id as number;
    return this.basicService.deleteFile(userId, id);
  }

  //获取最近查看文件/获取最近编辑文件

  //文件下载，需要和oss交流，请明确我们的后端一般是生成oss的链接返回给前端，让其进行上传/下载等操作

  //分享文件

  //查看文件后新增一条查看记录

  //编辑文件后
}
